package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("redis")
@RestController
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("setId")
    public String set(@RequestParam Integer id, @RequestParam String value) {
        redisTemplate.opsForValue().set(id, value);
        return "ok";
    }

    @RequestMapping("getValueById")
    public String getValueById(@RequestParam Integer id) {
        return redisTemplate.opsForValue().get(id).toString();
    }
}
